package com.rpay.common.enums;

/**
 * Title：
 * Description
 *
 * @author fxg06 on 2018/4/18
 * @version 1.0
 */
public enum PcsResultCode {
    /**
     * sys enum config
     */
    SUCCESS(0, "成功", "success"),

    /**
     * Token
     */
    ACCESS_TOKEN_NOT_EXISTED(10000, "accessToken不存在/过期", "accessToken not existed or expired"),
    REFRESH_TOKEN_NOT_EXISTED(10001, "refreshToken不存在", "refreshToken not exist"),
    REFRESH_TOKEN_ERROR(10002, "刷新token失败", "refresh token failed"),

    /**
     * 用户
     */
    USER_PASSWORD_ERROR(20101, "用户密码错误", "password error"),
    USER_PASSWORD_NULL(20102, "用户密码不能为空", "password cannot be empty"),
    USER_PASSWORD_MATCH(20103, "用户密码与新密码不一致", "The password does not match the new password"),
    USER_UPD_PWD_ERROR(20104, "用户修改密码失败", "modify password failed"),
    USER_PASSWORD_NOT_CONFIRM(20105, "新密码与确认密码不一致", "The new password is not consistent with the confirmation password"),
    USER_NOT_EXISTED(20109, "用户不存在", "user not existed"),
    USER_INVALID(20110, "无效用户", "invalid user"),
    USER_VERIFY_FAIL(20111, "身份验证失败", "user verify failed"),
    USER_PHONE_EXISTED(20112, "手机号已存在", "phone number existed"),
    USER_SECRET_NOT_EXISTED(20113, "用户谷歌密匙不存在", "google key not existed"),
    USER_SHARECODE_NOT_EXISTED(20114, "分享码不存在", "share code not existed"),
    USER_FREEZE_NOT_YOURSELF(20115, "不能冻结自己", "can not freeze self"),
    USER_NOT_HAVE_PERMISSION(20116, "没有权限", "permission denied"),
    USER_RIPPLE_NOT_ENOUGH(20117, "余额不足", "not sufficient funds"),
    USER_CANNOT_BUY(20119, "当前时间内不允许购买合约", "purchase contracts are not allowed at present time"),
    SMS_CODE_SAVE_FAIL(20120, "保存验证码失败", "save verify code failed"),

    BUSINESS_LEVEL_ERROR(20204, "用户等级错误", "user level error"),
    BUSINESS_USER_EXISTED(20205, "账号手机号码或者email已经存在", "phone number or email has existed"),
    BUSINESS_ROLE_EXISTED(20206, "角色名已经存在", "role has existed"),
    BUSINESS_RESOURCE_EXISTED(20207, "资源已存在", "resource has existed"),

    USER_MAIL_FAIL(20200, "邮件发送失败", "send email failed"),
    USER_MAIL_EXISTED(20201, "邮箱已存在", "email has existed"),

    /**
     * 短信
     */
    SMS_TYPE_MISMATCH(20300, "验证码类型不存在", "verify code types not exist"),
    SMS_CODE_FAIL(20301, "验证码错误", "verify code error"),
    SMS_CODE_EXPIRED(20302, "验证码失效", "verify code expired"),
    SMS_SEND_FAILED(20303, "验证码发送失败", "verify code send failed"),
    SMS_GOOGLE_FAIL(20304, "谷歌验证码错误", "google verify code error"),

    /**
     * 安全/授权错误
     */
    SECURITY_AUTHORIZE(20400, "未授权/公共参数错误", "unauthorized"),

    /**
     * 请求参数错误
     */
    NOT_FOUND_HANDLER(40100, "请求资源地址不存在", "request resource address does not exist"),
    PARAM_INVALID(40101, "参数错误", "parameter error"),
    METHOD_NOT_SUPPORT(40102, "请求方法错误", "request method error"),
    METHOD_TYPE_NOT_SUPPORT(40103, "请求类型不合法", "request type unlawful"),
    PARAM_LOSE(40104, "参数缺失", "parameter missing"),
    PARAM_TYPE_NOT_SUPPORT(40105, "参数类型不匹配", "parameter type mismatch"),


    /**
     * 服务器异常 (非手动抛出,此返回码由GlobalExceptionHandler判断非业务错误抛出)
     */
    ERROR_OPERATE(50000, "操作失败", "operation failed");


    private Integer code;

    private String desc;

    private String detail;

    PcsResultCode(Integer code, String desc, String detail) {
        this.code = code;
        this.desc = desc;
        this.detail = detail;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    /**
     * 查询异常类型
     *
     * @param code
     * @return enum pcs
     */
    public static PcsResultCode valueOf(Integer code) {
        for (PcsResultCode returnCode : values()) {
            if (code.equals(returnCode.code)) {
                return returnCode;
            }
        }
        throw new IllegalArgumentException("No matching constant for [" + code + "]");
    }
}
